﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace File_Operate_Program
{
    public partial class FrmCSV_Editor_Column : Form
    {
        public string ColumnName { get; set; }
        public string Notes = "请在此输入待编辑的列名！";
        public FrmCSV_Editor_Column()
        {
            InitializeComponent();
            this.StartPosition = FormStartPosition.CenterScreen;
        }

        private void FrmCSV_Editor_Column_Load(object sender, EventArgs e)
        {
            this.BtnOK.Click += new System.EventHandler(this.BtnOK_Click);
            this.BtnCancel.Click += new System.EventHandler(this.BtnCancel_Click);
            this.TxtEditorColumnName.Enter += new System.EventHandler(this.TxtEditorColumnName_Enter);
            this.TxtEditorColumnName.Leave += new System.EventHandler(this.TxtEditorColumnName_Leave);
            this.TxtEditorColumnName.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.TxtEditorColumnName_KeyPress);
        }

        private void BtnOK_Click(object sender, EventArgs e)
        {
            ColumnName = TxtEditorColumnName.Text;
            this.DialogResult = DialogResult.OK;
        }

        private void BtnCancel_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.Cancel;
        }

        private void TxtEditorColumnName_Leave(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(TxtEditorColumnName.Text))
            {
                TxtEditorColumnName.ForeColor = Color.DarkGray;
                this.TxtEditorColumnName.Text = Notes;
            }
        }

        private void TxtEditorColumnName_Enter(object sender, EventArgs e)
        {
            if (TxtEditorColumnName.Text == Notes)
            {
                TxtEditorColumnName.ForeColor = Color.Black;
                this.TxtEditorColumnName.Text = "";
            }
        }

        private void TxtEditorColumnName_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar == (Char)Keys.Enter)
            {
                BtnOK_Click(null, null);
            }
        }
    }
}
